module(..., package.seeall)

require "myUiWin"
require "cacheConfig"

PAGEID = 0

local backColor = 0x0000 -- 背景色
local action = ""
local counts = 0

local function show()
    disp.setcolor(0xFFFF)
    disp.setbkcolor(backColor)
    disp.clear()
    disp.drawrect(0, 22, 105, 23, 0x017E)
    disp.drawrect(110, 22, 160, 23, 0x06C0)

    if action == "restart" then
        disp.puttext(common.utf8ToGb2312("重启网关"), 2, 2)
    elseif action == "reset" then
        disp.puttext(common.utf8ToGb2312("恢复出厂设置"), 2, 2)
    elseif action == "info" then
        disp.puttext(common.utf8ToGb2312("系统信息"), 2, 2)
    end

    if action == "info" then
        disp.puttext(common.utf8ToGb2312("版本信息"),
                     ui_handle.getXPos(common.utf8ToGb2312("版本信息")), 40)
        disp.puttext(_G.VERSION, ui_handle.getXPos(_G.VERSION), 60)
        disp.puttext(rtos.get_fs_free_size(),
                     ui_handle.getXPos(rtos.get_fs_free_size()), 90)
    else
        disp.puttext(common.utf8ToGb2312("请按3下确认键执行"),
                     ui_handle.getXPos(
                         common.utf8ToGb2312("请按3下确认键执行")), 40)
    end

    disp.update()

end

function initPage(para)
    counts = 0
    action = para
    show()
end

function refresh() show() end

function onKey(value)
    if value == "enter" then
        counts = counts + 1
        if counts == 3 then
            if action == "restart" then
                sys.restart("user")
            elseif action == "reset" then
                -- 初始化nvm
                nvm.restore()
                -- 删除cache
                -- cacheConfig.deletData()
                sys.taskInit(function()
                    sys.wait(2000)
                    sys.restart("reset")        
                end)
            end
        end
    elseif value == "return" then
        myUiWin.openWin(ui_menu.PAGEID, "选择菜单")
    end
end
